package com.zhongxi.guoyuan.adapter.shopCart;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.entity.shopcart.AddressList;

import java.util.List;

/**
 * Created by Administrator on 2017/2/20.
 */

public class AddressAdapter extends BaseAdapter {

    private Context context;
    private List<AddressList.AddressData> list;
    private int type;

    public AddressAdapter(Context context, List<AddressList.AddressData> list, int type) {

        this.type = type;this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_edit_address, parent, false);
            holder = new ViewHolder();
            holder.tvContent = (TextView) convertView.findViewById(R.id.tvContent);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        if(null!=list.get(position)&&!"".equals(list.get(position))){
            AddressList.AddressData data = list.get(position);
            switch (type){
                case 1:
                    if(null!=data.getProvince()&&!"".equals(data.getProvince())){
                        holder.tvContent.setText(data.getProvince());
                    }else{
                        holder.tvContent.setText("");
                    }
                    break;
                case 2:
                    if(null!=data.getCity()&&!"".equals(data.getCity())){
                        holder.tvContent.setText(data.getCity());
                    }else{
                        holder.tvContent.setText("");
                    }
                    break;
                case 3:
                    if(null!=data.getPrefecture()&&!"".equals(data.getPrefecture())){
                        holder.tvContent.setText(data.getPrefecture());
                    }else{
                        holder.tvContent.setText("");
                    }
                    break;
                case 4:
                    if(null!=data.getValue()&&!"".equals(data.getValue())){
                        holder.tvContent.setText(data.getValue());
                    }else{
                        holder.tvContent.setText("");
                    }
                    break;
            }
        }
        return convertView;
    }

    class ViewHolder{
        private TextView tvContent;
    }
}
